<!--{include file="public/top" /}-->

<body class="layui-anim layui-anim-up">

<div class="x-body">
    <div class="layui-row clear pagesa">
        <p class="fl">>栏目管理</p>
    </div>
    <div class="layui-row" style="margin: 10px 0 -10px 0">
        <form class="layui-form layui-col-md12 x-so">

            <button class="layui-btn layui-btn-warm  fr" id="refresh" type="button" onclick="history.go(0)"><i class="layui-icon ">&#xe63f;</i>刷新</button>
            <button class="layui-btn layui-btn-normal fr" id="add" type="button"><i class="layui-icon ">&#xe654;</i>添加顶级栏目</button>
        </form>
    </div>

    <table class="layui-table layui-form">
        <thead>
        <tr>
            <th width="70">ID</th>
            <th width="500">名称</th>
            <th width="150">创建时间</th>
            <th width="50">排序</th>
            <th>操作</th>
        </thead>
        <tbody class="x-cate">
        <!--{volist name="list" id="v"}-->
        <tr cate-id='<!--{$v.id}-->' fid='<!--{$v.topid}-->' >
            <td id="id"><!--{$v.id}--></td>
            <td style="padding: 9px <!--{$v.padding}-->px">
                <i class="layui-icon x-show" status='true'>&#xe623;</i>
                <!--{$v.name}-->
            </td>
            <td>
                <!--{$v.create_time}-->
            </td>
            <td class="sort" value="<!--{$v.id}-->"><!--{$v.sort}--></td>
            
            <td class="td-manage">
                <button class="layui-btn layui-btn layui-btn-xs up" value="<!--{$v.id}-->" ><i class="layui-icon">&#xe642;</i>编辑</button>
                <button class="layui-btn layui-btn-warm layui-btn-xs addlm" value="<!--{$v.id}-->" ><i class="layui-icon">&#xe642;</i>添加子栏目</button>
                <a class="layui-btn layui-btn-warm layui-btn-xs wzlist" href="/admin/newslist.html?lanmuid=<!--{$v.id}-->"><i class="layui-icon">&#xe642;</i>文章</a>
                <button class="layui-btn-danger layui-btn layui-btn-xs del" value="<!--{$v.id}-->"  ><i class="layui-icon">&#xe640;</i>删除</button>
            </td>
        </tr>
        <!--{/volist}-->
        </tbody>
    </table>
</div>
<style type="text/css">

</style>
<script>
    var addurl = '/admin/newslanmu/add.html';
    var delurl = '/admin/nav/del';
    var upurl = '/admin/newslanmu/edit.html';
    var sortUrl = '/admin/nav/sort';
    var getOneurl = '/admin/nav/getOne';
    layui.use(['form'], function(){
        form = layui.form;

    });
    //添加
    $('#add').click(function () {
        layer.open({
            type: 2,
            area:  ["1000px","600px"],
            fix: false, //不固定
            maxmin: true,
            shade:0.4,
            title: '添加',
            content: addurl,
            end: function(){
                history.go(0)
            }
        });
    });
    $('.addlm').click(function () {
        var data = $(this).val();
        layer.open({
            type: 2,
            area:  ["1000px","600px"],
            fix: false, //不固定
            maxmin: true,
            shade:0.4,
            title: '添加',
            content: addurl+"?id="+data,
            end: function(){
            }
        });
    });
    $('.up').click(function () {

        var data = $(this).val();
        layer.open({
            type: 2,
            area:  ["1000px","600px"],
            fix: false, //不固定
            maxmin: true,
            shade:0.4,
            title: '编辑',
            content: upurl+"?id="+data,
            end: function(){

            }
        });
    });
    $('.sort').click(function () {
        var data = $(this).attr('value');
        var t = $(this);
        var sort = $(this).text();
        layer.prompt({
            formType: 2
            ,title: '修改排序'
            ,value: sort
        }, function(value, index){
            layer.close(index);
            $.ajax({
                type: "get",
                dataType: "json",
                url: sortUrl+"/id/"+data+"/sort/"+value,
                success: function (res) {
                    var success = JSON.parse(res);
                    if(success.code===200){
                        t.text(value);
                        layer.msg(success.msg, {
                            time: 1000
                        });
                    }else {
                        layer.msg(success.msg);
                    }
                }
            });

        });
    });
    $('.del').click(function () {
        var id = $(this).val();
        var t = $(this);
        layer.confirm('真的删除么', function(index){
            $.ajax({
                type: "POST",
                dataType: "json",
                url: delurl,
                data: {'id': id},
                success: function (res) {
                    var success = JSON.parse(res);
                    if(success.code===200){
                        layer.msg(success.msg);
                        t.parents("tr").remove();
                    }else {
                        layer.msg(success.msg)
                    }

                }
            });

        });
    });
</script>

</body>

</html>